# Maintainer: Andrea Zagli <andrea.zagli.free@gmail.com>

_realname=uhttpmock
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.5.3
pkgrel=5
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
pkgdesc="uhttpmock is a HTTP web service mocking project for projects which use libsoup (mingw-w64)"
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-libsoup")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
            "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
            "${MINGW_PACKAGE_PREFIX}-vala"
            "${MINGW_PACKAGE_PREFIX}-autotools"
            "${MINGW_PACKAGE_PREFIX}-gtk-doc")
options=('strip' 'staticlibs' '!debug')
license=("LGPL 2.1")
url="https://tecnocode.co.uk/"
source=(https://tecnocode.co.uk/downloads/${_realname}/${_realname}-${pkgver}.tar.xz
        0001-wsock.patch
        0002-give-cc-to-gir-scanner.all.patch)
sha256sums=('90843223c3a30bdb7f1eb3442373a03fee425af85a9df289cd687698ccff112f'
            '61a3563903d979a93514e09582400ed0647e3029a0632d5c6fbbd0f0589ba809'
            'd12318d529f768ddfb2107e249d9c181e009dc1e62fdcced4c3397ead36e4845')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/0001-wsock.patch
  patch -p1 -i ${srcdir}/0002-give-cc-to-gir-scanner.all.patch

  WANT_AUTOCONF=2.69 autoreconf -fiv
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}

  ../${_realname}-${pkgver}/configure \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --libexecdir=${MINGW_PREFIX}/lib

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
